package com.ssm.zhihu_ssm.service.impl;

import com.ssm.zhihu_ssm.dao.QuestionDao;
import com.ssm.zhihu_ssm.entity.Classify;
import com.ssm.zhihu_ssm.entity.Question;
import com.ssm.zhihu_ssm.service.QuestionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service(value = "QuestionService")
public class QuestionServiceImpl implements QuestionService {

    @Resource
    private QuestionDao questionDao;

    @Override//插入问题
    public void insertQuestion(int uid, String title, String content_question, int cid) {
        Question question = new Question();
        question.setUid(uid);
        question.setTitle(title);
        question.setContent_question(content_question);
        questionDao.insertQuestion(question);
        questionDao.insertQuestionClassify(question.getId(), cid);
    }

    @Override
    public void followQuestion(int uid, int question_id, boolean isFollow) {
        if(isFollow) {
            questionDao.deleteFollowQuestion(uid, question_id);
        }else {
            questionDao.followQuestion(uid, question_id);
        }
    }

    @Override//得到用户所有问题
    public List<Question> getQuestionByUserId(int id) {
        return questionDao.getQuestionByUserId(id);
    }

    @Override//根据主题id查找问题
    public List<Question> getQuestionByClassifyId(int classify_id) {
        if(classify_id == 0){
            return questionDao.getQuestionByAllClassify();
        }
        return questionDao.getQuestionByClassifyId(classify_id);
    }

//    @Override
//    public List<Question> getQuestionByAllClassify() {
//        return questionDao.getQuestionByAllClassify();
//    }

    @Override//根据问题id得到问题信息
    public Question getQuestionByQuestionId(int question_id, int uid) {
        return questionDao.getQuestionByQuestionId(question_id, uid);
    }

    @Override
    public Map<String,Object> getClassifyNameByQuestionId(int question_id) {
        return questionDao.getClassifyNameByQuestionId(question_id);
    }

    @Override
    public List<Classify> getClassify() {
        return questionDao.getClassify();
    }

    @Override
    public void addQuestionSkimNum(int question_id) {
        questionDao.addQuestionSkimNum(question_id);
    }

}
